# node心跳检测线程类
import logging
import threading
import time
from datetime import datetime

import requests

from app.env import LOT_VEHICLE_TIME

log = logging.getLogger('error_msg')


def get_10_vehicle_list():
    try:
        url = 'http://127.0.0.1:5200/lot/get10VehicleList'
        response = requests.post(url)
        res_data = response.json()
        if res_data['code'] == 200:
            return True
        return False
    except Exception as e:
        log.error(f"拉去总装 10点上线序列失败, 异常：" + str(e))
        return False


class Get10VehicleThread(threading.Thread):
    def __init__(self):
        super(Get10VehicleThread, self).__init__()

    def run(self):
        while True:
            try:
                print("拉去总装 10点上线序列", datetime.now().strftime('%Y-%m-%d %h:%M:%SZ'))
                get_10_vehicle_list()
                print("拉去总装 10点上线序列 完成", datetime.now().strftime('%Y-%m-%d %h:%M:%SZ'))
            except Exception as e:
                log.error('拉去总装 10点上线序列失败, 异常：' + str(e))
            time.sleep(LOT_VEHICLE_TIME)
